#{extends 'main.html' /}
#{set title:'MyNewEv' /}

#{if user}
<div id='cssmenu'>
<ul>
   <li><a href='/home'><span>Home</span></a></li>
   <li><a href='/category'><span>Create event</span></a></li>
   <li><a href='/myevents'><span>My events</span></a></li>
   <li><a href='/registeredevents'><span>Registered events</span></a></li>
</ul>
</div>
#{/if}
		<br/>
		<center>
		<nav-header>
			<a href="/trips"> Trips </a>
			<a href="/sports"> Sport </a>
			<a href="/culture"> Culture </a>
			<a href="/entertainment"> Entertainment </a>
			<a href="/night_life"> Night life </a>
			<a href="/learning"> Learning </a>
		</nav-header>
		</center>
		<div class="container">
			<!--<div id="adds">adds
			</div>-->

<div class="detailedevent" >
	<div class=${event.categoryString} >
		<h4> ${event.title} </h4>
		<div class="photo"></div>
		<p class="eventcontent">
			Author: ${event.author.userName} <br/>
			Category: ${event.category} <br/>
			Date: ${(event.eventDate).format('dd MMMM yyyy')} <br/>
			Location: ${event.location} <br/>
			Description: ${event.description} <br/>
			Registered: ${event.registeredUsers.size()} <br/>
		</p>
	</div>
</div>	

#{if event.author.equals(user)}
	<a href="@{EventManager.editevent(event.id)}">Edit event</a> <br/>
	<a href="@{EventManager.deleteEvent(event.id)}">Delete event</a> <br/>
	
	#{form @EventManager.sendInvitation(event.id)}

	Send invitation for event: ${event.title} <br/>
	<b>Select User:</b><br /><br />
	<select name="Users" size="1">
		#{list items:users, as:'invitedUser'}
		   <option>${invitedUser.userName}</option>
		#{/list}
	</select>
	<br /><br />
	<input type="submit" value="Send invitation">
	#{/form}
	
#{/if}
#{else}
	#{if event.registeredUsers.contains(user)}
		Registered <br/>
		<a href="@{EventManager.unregisterevent(event.id)}">Unregister</a> <br/>
	#{/if}
	#{else}
		#{if user}
			#{if user.invitations.contains(event)}
				<a href="@{EventManager.registerevent(event.id)}">Accept invitation</a>
				<a href="@{EventManager.rejectevent(event.id)}">Reject invitation</a>
			#{/if}
			#{else}
				<a href="@{EventManager.registerevent(event.id)}">Register to this event</a> <br/>
			#{/else}
		#{/if}
	#{/else}
#{/else}

<span class="event-comments">
	&nbsp;|&nbsp; 
 	${event.comments.size() ?: 'no'} 
	comment${event.comments.size().pluralize()}
    #{list items:event.comments, as:'comment'}
    	<p>
    		author: ${comment.author.userName} <br/>
    		content: ${comment.content}
    	</p>
    #{/list}
</span>

#{form @EventManager.postComment(event.id)}
	<span>
		<label for "content">content:</label>
		<textarea type="text" name="content" id="content" value="" rows="5" cols="100"></textarea> <br/>
	</span>
	<span>
        <input type="submit" value="Submit your comment" /> <br/>
    </span>
#{/form}

</div>